//引入axios实例
import request from "@/utils/request"

//1.获取一级列表
//获取一级列表返回值每一项类型
export interface reqCategoryReturnItemType {
    id: number,
    name: string,
    category1Id?: number 
    category2Id?: number
}
//获取一级列表返回值的类型
export type reqCategoryReturnType  = reqCategoryReturnItemType[]
export const requestCategory1 = () => {
    return request.get<any , reqCategoryReturnType>(`/admin/product/getCategory1`)
}

//2.获取二级列表
export const requestCategory2 = (category1Id: number) => {
    return request.get<any , reqCategoryReturnType>(`/admin/product/getCategory2/${category1Id}`)
}

//3.获取三级列表请求
export const requestCategory3 = (category2Id: number) => {
    return request.get<any , reqCategoryReturnType>(`/admin/product/getCategory3/${category2Id}`)
}




//4.获取商品属性列表请求
export interface reqAttrValueType {
    id?: number,
    valueName: string,
    attrId: number,
    isEdit?: boolean
}
//获取商品属性请求每一项类型
export interface reqAttrItemType {
    id?: number,
    attrName: string,
    categoryId: number,
    categoryLevel: number,
    attrValueList: reqAttrValueType[],
    attrIdValueId?: string
}
//获取商品属性请求返回值类型
export type reqAttrListType = reqAttrItemType[]
export const requestGetAttrList = (
    category1Id: number,
    category2Id: number,
    category3Id: number,
) => {
    return request.get<any , reqAttrListType>(`/admin/product/attrInfoList/${category1Id}/${category2Id}/${category3Id}`)
}

//5删除某个属性
export const requestDeleteAttr = (attrId: number) => {
    return request.delete<any, null>(`/admin/product/deleteAttr/${attrId}`);
  };
  
//6.新增或修改属性
export const requestUpdateOrAddAttr = (newAttr: reqAttrItemType) => {
    return request.post<any, null>(`/admin/product/saveAttrInfo`, newAttr);
};
